package com.ChildDoodle;

import android.content.Context;
import android.telephony.TelephonyManager;

import com.mime.qweibo.QAsyncHandler;
import com.mime.qweibo.QAsyncHttpClient;

public class ClientUpload implements QAsyncHandler {
	private static ClientUpload instance = new ClientUpload();

	public static ClientUpload getInstance() {
		return instance;
	}

	@Override
	public void onThrowable(Throwable t, Object cookie) {
		System.err.println(cookie.toString() + ":" + t.getLocalizedMessage());

	}

	@Override
	public void onCompleted(int statusCode, String content, Object cookie) {
		System.out.println("success:" + cookie.toString());
		System.out.println("code:" + statusCode);
		System.out.println("content:" + content);
	}

	public boolean clientLanuchUpload() {
		QAsyncHttpClient asyncHttp = new QAsyncHttpClient();
		Context contextDoodle = DataCenter.getInstance().GetAppContext();

		TelephonyManager telephonyManager = (TelephonyManager) contextDoodle
				.getSystemService(contextDoodle.TELEPHONY_SERVICE);
		String strIMEI = telephonyManager.getDeviceId();

		String strQuery = "machineId=" + strIMEI + "&phoneNum="
				+ telephonyManager.getLine1Number() + "&osVersion="
				+ android.os.Build.VERSION.RELEASE;

		return asyncHttp.httpGet("http://childdoodle.sinaapp.com/userinfo.php",
				strQuery, this, "clientLanuchUpload");
	}

	public boolean Login() {
		QAsyncHttpClient asyncHttp = new QAsyncHttpClient();
		return asyncHttp.httpGet("http://childdoodle.sinaapp.com/login.php",
				"", this, "Login");
	}

	public boolean Loginout() {
		QAsyncHttpClient asyncHttp = new QAsyncHttpClient();
		return asyncHttp.httpGet("http://childdoodle.sinaapp.com/logout.php",
				"", this, "Loginout");
	}

}
